#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cstring>
#include<algorithm>
#define x first
#define y second
using namespace std;
using pii = pair<int, int>;
const int N = 100010, mod = 99999997;
pii a[N], b[N];
int q[N], tmp[N];
int n, ans;
void merge_sort(int a[], int l, int r)
{
    if (l >= r) return;
    int mid = l + r >> 1;
    merge_sort(a, l, mid), merge_sort(a, mid + 1, r);
    int k = 0, i = l, j = mid + 1;
    while (i <= mid && j <= r)
    {
        if (a[i] <= a[j]) tmp[k++] = a[i++];
        else
        {
            tmp[k++] = a[j++];
            ans = (ans + mid - i + 1) % mod;
        }
    }
    while (i <= mid) tmp[k++] = a[i++];
    while (j <= r) tmp[k++] = a[j++];
    for (int i = l, j = 0; i <= r;) a[i++] = tmp[j++];
}
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i].x;
        a[i].y = i;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> b[i].x;
        b[i].y = i;
    }
    sort(a, a + n), sort(b, b + n);
    for (int i = 0; i < n; i++) q[a[i].y] = b[i].y;
    merge_sort(q, 0, n - 1);
    cout << ans << endl;
    return 0;
}